package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysSinger;
import com.ruoyi.system.service.ISysSingerService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 歌手Controller
 * 
 * @author Johnson
 * @date 2025-04-30
 */
@RestController
@RequestMapping("/system/singer")
@RequiredArgsConstructor
public class SysSingerController extends BaseController {

    private final ISysSingerService sysSingerService;

    /**
     * 查询歌手列表
     */
    @PreAuthorize("@ss.hasPermi('system:singer:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysSinger sysSinger) {
        startPage();
        List<SysSinger> list = sysSingerService.selectSysSingerList(sysSinger);
        return getDataTable(list);
    }

    /**
     * 导出歌手列表
     */
    @PreAuthorize("@ss.hasPermi('system:singer:export')")
    @Log(title = "歌手", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysSinger sysSinger) {
        List<SysSinger> list = sysSingerService.selectSysSingerList(sysSinger);
        ExcelUtil<SysSinger> util = new ExcelUtil<SysSinger>(SysSinger.class);
        util.exportExcel(response, list, "歌手数据");
    }

    /**
     * 获取歌手详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:singer:query')")
    @GetMapping(value = "/{singerId}")
    public AjaxResult getInfo(@PathVariable("singerId") Long singerId) {
        return success(sysSingerService.selectSysSingerBySingerId(singerId));
    }

    /**
     * 新增歌手
     */
    @PreAuthorize("@ss.hasPermi('system:singer:add')")
    @Log(title = "歌手", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysSinger sysSinger) {
        return toAjax(sysSingerService.insertSysSinger(sysSinger));
    }

    /**
     * 修改歌手
     */
    @PreAuthorize("@ss.hasPermi('system:singer:edit')")
    @Log(title = "歌手", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysSinger sysSinger) {
        return toAjax(sysSingerService.updateSysSinger(sysSinger));
    }

    /**
     * 删除歌手
     */
    @PreAuthorize("@ss.hasPermi('system:singer:remove')")
    @Log(title = "歌手", businessType = BusinessType.DELETE)
	@DeleteMapping("/{singerIds}")
    public AjaxResult remove(@PathVariable Long[] singerIds) {
        return toAjax(sysSingerService.deleteSysSingerBySingerIds(singerIds));
    }
}
